package com.group.mall.controller;

import com.group.mall.domain.POJO.Goods;
import com.group.mall.domain.VO.GoodsVO;
import com.group.mall.domain.VO.ShowGoodsVO;
import com.group.mall.service.GoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "商品管理相关接口")
@RestController
@RequestMapping("/items")
@RequiredArgsConstructor
@Slf4j
public class GoodsController {

    @Autowired
    private GoodsService itemService;

    //显示所有商品
    @GetMapping("/listAll")
    public List<GoodsVO> queryAllItems() {
        return itemService.queryAllGoods();
    }

    @ApiOperation("查询热销商品")
    @GetMapping("/hot")
    public List<Goods> queryHotItems() {
        return itemService.queryHotGoods();
    }

    @GetMapping("/search/{searchInfo}")
    public List<GoodsVO> queryItemsByName(@PathVariable("searchInfo") String searchInfo) {
        log.info("searchInfo: " + searchInfo);
        return itemService.queryItems(searchInfo);
    }

    @ApiOperation("根据收索信息模糊查询商品")
    @GetMapping("/choose/{searchInfo}/{chooseType}")
    public List<GoodsVO> queryItemsByChooseType(@PathVariable("searchInfo") String searchInfo,@PathVariable("chooseType") Integer chooseType) {
        log.info("searchInfo: " + searchInfo);
        log.info("chooseType: " + chooseType);
        //根据chooseType筛选商品:1评价，2销量，3价格低，4价格高,5没有查询项
        return itemService.queryItemsByName(searchInfo,chooseType);
    }

    //根据id查询商品详情
    @GetMapping("/{id}")
    public Goods queryItemById(@PathVariable("id") Integer id) {
        return itemService.queryItemById(id);
    }

    @GetMapping("/show/{id}")
    public List<ShowGoodsVO> showItemById(@PathVariable("id") Integer id) {
        return itemService.showItemById(id);
    }
}
